package com.leyou.item.controller;

import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.Impl.SpecificationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author: Saka
 * Date: 2019/1/20
 * Time: 15:49
 */
@RestController
@RequestMapping("spec")
public class SpecificationContorller {
    @Autowired
    private SpecificationServiceImpl specificationService;

    @GetMapping("groups/{cid}")
    public ResponseEntity<List<SpecGroup>> querySpecGroups(@PathVariable("cid") Long cid) {
        List<SpecGroup> list = this.specificationService.querySpecGroups(cid);
        if (list != null && 0!=list.size()) {
            return ResponseEntity.ok(list);

        }
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }


    @GetMapping("params")
    public ResponseEntity<List<SpecParam>> querySpecParam(
            @RequestParam(value = "gid",required = false)Long gid,
            @RequestParam(value = "cid",required = false)Long cid) {


        List<SpecParam> list = this.specificationService.querySpecParam(gid,cid);
        if (list != null && 0!=list.size()) {
            return ResponseEntity.ok(list);

        }
        return ResponseEntity.status(HttpStatus.NOT_FOUND).build();

    }

    //TODO 添加--增删改 功能
}
